package com.ship.boats.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ship.boats.domain.ConShipping;
import com.ship.boats.domain.IhsShipBase;
import com.ship.boats.mapper.ConShippingMapper;
import com.ship.boats.service.ConShippingService;
import com.ship.common.core.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <b>ConShippingServiceImpl</b>
 *
 * @description: ConShippingServiceImpl <br>
 * @date: 2024/4/24 16:14 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Service
public class ConShippingServiceImpl extends ServiceImpl<ConShippingMapper, ConShipping> implements ConShippingService {
    private static final Logger logger = LoggerFactory.getLogger(ConShippingServiceImpl.class);

    @Override
    public void updateConShipping(IhsShipBase ihsShipBase) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("imo",ihsShipBase.getImo());
        List<ConShipping> shippingList = baseMapper.selectList(queryWrapper);
        if (CollectionUtil.isNotEmpty(shippingList)){
            shippingList.forEach(item -> {
                if (StringUtils.isEmpty(item.getClassificationSociety())){
                    item.setClassificationSociety(ihsShipBase.getClassificationSociety());
                }
                if (StringUtils.isEmpty(item.getClassificationSocietyCode())){
                    item.setClassificationSocietyCode(ihsShipBase.getClassificationSocietyCode());
                }
                if (StringUtils.isNotEmpty(item.getPrimeMoverDescriptiveNarrative())){
                    item.setPrimeMoverDescriptiveNarrative(ihsShipBase.getPrimeMoverDescriptiveNarrative());
                }
                baseMapper.updateById(item);
            });

        }
    }
}
